﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Huirui.Cavan.Domain.MainBoundedContext.SystemModule;
using Huirui.Cavan.Domain.Seedwork;

namespace Huirui.Cavan.Domain.MainBoundedContext.PurchaseModule
{
    public class PurchaseManager
    {
        private Employee _employee;

        public PurchaseManager(Employee employee)
        {
            this._employee = employee;
        }

        public BoolGenericResult<PurchaseOrder> CloseOrReopenPurchaseOrder(PurchaseOrder purchaseOrder, PurchaseIdentifier.StockInStatus status)
        {
            BoolGenericResult<PurchaseOrder> result = new BoolGenericResult<PurchaseOrder>();

            if (status == PurchaseIdentifier.StockInStatus.Closed)
            {
                if (purchaseOrder.StockInStatus != PurchaseIdentifier.StockInStatus.UnIn)
                {
                    result.IsSuccess = false;
                    if (purchaseOrder.StockInStatus == PurchaseIdentifier.StockInStatus.Closed)
                    {
                        result.Messages.Add("采购订单已被关闭");
                    }
                    else
                    {
                        result.Messages.Add("采购订单已入库，不能关闭");
                    }
                    return result;
                }

                purchaseOrder.StockInStatus = PurchaseIdentifier.StockInStatus.Closed;
            }
            else if (status == PurchaseIdentifier.StockInStatus.UnIn && purchaseOrder.StockInStatus == PurchaseIdentifier.StockInStatus.Closed)
            {
                purchaseOrder.StockInStatus = status;
            }

            result.Object = purchaseOrder;

            return result;
        }
    }
}
